package com.shengyuan.manage_os.old.ying.erpm;

import org.json.JSONException;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.old.ying.erpm.controls.PictureButton;
import com.shengyuan.manage_os.old.ying.erpm.tasks.Submit_System_Setting_Data_Task;
import com.shengyuan.manage_os.old.ying.erpm.util.Utility;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class Actual_Form_FangJieSuan extends BaseActivity {

	private PictureButton PictureButton_chang, PictureButton_kuan, PictureButton_gao;
	private EditText chang, kuan, gao;

	@Override
	public void onClick(View view) {
		super.onClick(view);
	}
	@Override
	protected void onResume() {
		super.onResume();
		if (PictureButton_chang!=null) {
			PictureButton_chang.postInvalidate();
		}
		if (PictureButton_kuan!=null) {
			PictureButton_kuan.postInvalidate();
		}
		if (PictureButton_gao!=null) {
			PictureButton_gao.postInvalidate();
		}
		
		
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actual_form_changkuangao);
		InitControls();
	}

	@Override
	protected void SaveJsonData() {
		try {
			IsJson1 = true; mFinished = 1 ;
			JsonMyID();
			getCar();
			//getZhuangdi();
			getXiedi();
			getTask();
			getCaiLiao();
			
			getChangKuanGao();
			
			getGPS();
			getCurrentUser();		
			getMemo();
			JsonPicture();
			JsonPicture_Ext();
			
		}catch (Exception e) {
		}
	}
	
	protected void getChangKuanGao() throws JSONException {
		if (chang!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_chang), chang.getText().toString());
		}
		if (kuan!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_kuan), kuan.getText().toString());
		}
		if (gao!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_gao),gao.getText().toString());
		}
		
		//价格保存
		if (Submit_System_Setting_Data_Task.mID>=0) {
			Double mm = Double.parseDouble(chang.getText().toString()) *  Double.parseDouble(kuan.getText().toString()) *  Double.parseDouble(gao.getText().toString());
			String YuSuanJiaGe = Submit_System_Setting_Data_Task.J_GONGCHENGMINGCHENG_GC.getJSONObject(Submit_System_Setting_Data_Task.mID).getString("YuSuanJiaGe");
			int pmm = (int)(mm * Double.parseDouble(YuSuanJiaGe));
			mJson.put( getString(R.string.title_actual_form_yusuanjiage),  pmm);
			mJson.put( getString(R.string.title_actual_form_jiage),  (mm+""));
		}
	}

	protected void JsonPicture_Ext() throws JSONException {
		if (PictureButton_chang!=null) {
			mJson.put( PictureButton_chang.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_chang.mFileName);
		}
		if (PictureButton_kuan!=null) {
			mJson.put( PictureButton_kuan.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_kuan.mFileName);
		}
		if (PictureButton_gao!=null) {
			mJson.put( PictureButton_gao.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_gao.mFileName);
		}
	}	
	@Override
	protected void SaveSelfPic(String sPath) {
		try {
			CopyPicDest(PictureButton_Car, sPath);
			CopyPicDest(PictureButton_Chexing, sPath);
			CopyPicDest(PictureButton_CaiLiao, sPath);
			CopyPicDest(PictureButton_chang, sPath);
			CopyPicDest(PictureButton_kuan, sPath);
			CopyPicDest(PictureButton_gao, sPath);
		} catch (Exception e) {
			Utility.MessageBox(this,e.getMessage());
		}
	}

	@Override
	public void Back() {
		super.Back();
	}

	@Override
	public void InitControls() {
		super.InitControls();
		PictureButton_chang = (PictureButton) findViewById(R.id.PictureButton_changdu);
		PictureButton_kuan = (PictureButton) findViewById(R.id.PictureButton_kuandu);
		PictureButton_gao = (PictureButton) findViewById(R.id.PictureButton_gaodu);
		
		chang = (EditText) findViewById(R.id.editText_chang);
		kuan = (EditText) findViewById(R.id.editText_shengshu);
		gao = (EditText) findViewById(R.id.editText_gao);
	}
	
	@Override
	public Boolean IsPassed() {
		if (super.IsPassed()) {
			if(!CheckEditNumber(chang))
				return false;
			if(!CheckEditNumber(kuan))
				return false;
			if(!CheckEditNumber(gao))
				return false;
			if (!PictureButton_Car.IsExist()) {
				Utility.MessageBox(this, PictureButton_Car.FIELD );
				return false;
			}
//			if (!(PictureButton_Chexing=null) && !PictureButton_Chexing.IsExist()) {
//				Utility.MessageBox( PictureButton_Chexing.FIELD );
//				return false;
//			}		
			if (!PictureButton_CaiLiao.IsExist()) {
				Utility.MessageBox( this,PictureButton_CaiLiao.FIELD );
				return false;
			}
			if (!PictureButton_chang.IsExist()) {
				Utility.MessageBox(this, PictureButton_chang.FIELD );
				return false;
			}
			if (!PictureButton_kuan.IsExist()) {
				Utility.MessageBox(this, PictureButton_kuan.FIELD );
				return false;
			}
			if (!PictureButton_gao.IsExist()) {
				Utility.MessageBox(this, PictureButton_gao.FIELD );
				return false;
			}			
			return true;
		}else {
			return false;
		}
	}

}
